#ifndef GEOCACHING_H
#define GEOCACHING_H

#include <QList>
#include <QDateTime>
#include "constants.h"
#include "geocoordinates.h"
#include "trackpoint.h"
#include "track.h"
#include "serialportsettings.h"
#include "gps.h"
#include "trackthread.h"
#include "point.h"
#include "route.h"
#include "map.h"
#include "gpxmanager.h"

// Основной класс, управляющий работой программы.

class Geocaching: public QObject
{
    Q_OBJECT

public:
    Geocaching(void);
    ~Geocaching();
    void LoadData(void);
    void SaveData(void) const;

    unsigned long AddPoint(Point*);
    bool EditPoint(const unsigned long&, Point*);
    bool GetPoint(const unsigned long&, Point*) const;
    bool DeletePoint(const unsigned long&);

    bool AddRoute(Route*, const bool& = false);
    bool EditRoute(const unsigned long&, Route*, const bool& = false);
    bool GetRoute(const unsigned long&, Route*) const;
    bool DeleteRoute(const unsigned long&);
    bool SetCurrentRoute(const unsigned long &aID);
    unsigned long GetCurrentRouteID(void) const;
    bool GetCurrentRoute(Route*) const;

    bool AddMap(Map*, const bool& = false);
    bool EditMap(const unsigned long&, Map*, const bool& = false);
    bool GetMap(const unsigned long&, Map*) const;
    bool DeleteMap(const unsigned long&);
    bool SetCurrentMap(const unsigned long&);
    unsigned long GetCurrentMapID(void) const;
    bool GetCurrentMap(Map*) const;

    bool GetTrack(const unsigned long&, Track*) const;
    bool DeleteTrack(const unsigned long&);
    bool SetCurrentTrack(const unsigned long &aID);
    unsigned long GetCurrentTrackID(void) const;
    bool GetCurrentTrack(Track*) const;
    void StartAutoTrackRecord(void);
    unsigned long StopAutoTrackRecord(const QString& = "", const bool& = false, const bool& = false);
    void StartManualTrackRecord(void);
    void AddManualTrackPoint(void);
    unsigned long StopManualTrackRecord(const QString& = "", const bool& = false, const bool& = false);
    bool GetManualTrackStatus(void) const;
    bool GetAutoTrackStatus(void) const;

    QList <Point> GetPointList(void) const;
    QList <Route> GetRouteList(void) const;
    QList <Track> GetTrackList(void) const;
    QList <Map> GetMapList(void) const;

    ReceiverStatus GetGPSStatus(void) const;
    bool SwitchGPS(const bool&);
    bool SetupGPS(const SerialPortSettings&, const QString&) const;
    bool GPSInfo(nmeaINFO&);
    bool GetCoordinates(GeoCoordinates&) const;
private:
    unsigned long lastPointID, lastRouteID, lastTrackID, lastMapID;
    unsigned long currentRouteID, currentMapID, currentTrackID;
    GPS *mainReceiver;
    QList <Point> mainPointList;
    QList <Route> mainRouteList;
    QList <Track> mainTrackList;
    QList <Map> mainMapList;
    Track *manualTrack, *autoTrack;
    bool manualTrackStatus, autoTrackStatus;
    TrackThread autoTrackThread;
signals:
    void CoordinatesChanged(void);
    void PointAdded(const Point&);
    void PointEdited(const Point&);
    void PointDeleted(const unsigned long&);
    void RouteAdded(const Route&);
    void RouteEdited(const Route&);
    void RouteDeleted(const unsigned long&);
    void CurrentRouteChanged(void);
    void MapAdded(const Map&);
    void MapEdited(const Map&);
    void MapDeleted(const unsigned long&);
    void CurrentMapChanged(void);
    void TrackAdded(const Track&);
    void TrackDeleted(const unsigned long&);
    void CurrentTrackChanged(void);
};

#endif // GEOCACHING_H
